package dyyx.util;

import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ResultSetMeta {
	
	public final int columnCount;
	
	public final List<ColumnInfo> columns;
	

	public ResultSetMeta(ResultSetMetaData rsmd)throws SQLException{
		
		this.columnCount = rsmd.getColumnCount();
		List<ColumnInfo> columnList = new ArrayList<ColumnInfo>();
		
		for(int i=1;i<=columnCount;i++){
			ColumnInfo columnInfo = new ColumnInfo(rsmd,i);
			columnList.add(columnInfo);
		}
		
		this.columns = Collections.unmodifiableList(columnList);

	}
		
	@Override
	public String toString(){	
		Map<String,Object> map = new HashMap<String,Object>();		
		map.put("columnCount", columnCount);
		map.put("columns", columns);
		return map.toString();
	}	
	
}
